﻿
-- =============================================
-- Author:		<Author,XFL>
-- Create date: <Create Date,2011 12>
-- Description:	<Description,创建 账号 到表：aspnet_Users>
-- =============================================




CREATE PROCEDURE [dbo].[proc_Users_Create]
	(
		@UserName nvarchar(50),
		@Password nvarchar(256),
		@Name nvarchar(50),
		@CompanyId int,
		@DepartmentId int,
		@Email nvarchar(50),
		@RTX nvarchar(50),
		@IsLockout bit,
		@UserInRoles nvarchar(2000),
		@RootId NVARCHAR(50)
	)
AS
begin
--	if(@UserInRoles='')
--	set @UserInRoles =NULL
	Insert Into aspnet_Users(UserName,Password,RTX,Email,CompanyId,[Name],IsLockout,DepartmentId,UserInRoles,rootid)
	Values(@UserName,@Password,@RTX,@Email,@CompanyId,@Name,@IsLockout,@DepartmentId,@UserInRoles,@RootId)

--如果有关联员工，将关联的员工的rootid同时修改 2014.5.8
if(@RootId<>'')
begin
	update aspnet_Users set rootid=@RootId where username=@RootId
end


--	
--	declare @UserId int
--	Set @UserId=(Select @@Identity)
--	Declare @i int
--	Set @i=0
--	while(@i<len(@RoleList))
--	begin
--	Insert Into aspnet_UsersInRoles(UserId,RoleId)Values(@UserId, substring(@RoleList,@i,charindex(',',@RoleList,@i)-@i))
--	Set @i=charindex(',',@RoleList,@i)+1
--	end
end
	RETURN

----
----set ANSI_NULLS ON
----set QUOTED_IDENTIFIER ON
----go
----
----ALTER PROCEDURE [dbo].[Users_Create]
----	(
----		@UserName nvarchar(50),
----		@Password nvarchar(256),
----		@RTX nvarchar(50),
----		@Email nvarchar(50),
----		@CompanyId int,
----		@Name nvarchar(50),
----		@IsLockout bit,
----		@RoleList nvarchar(2000)
----	)
----AS
----begin
----	Insert Into aspnet_Users(UserName,Password,RTX,Email,CompanyId,[Name],IsLockout)Values(@UserName,@Password,@RTX,@Email,@CompanyId,@Name,@IsLockout)
----	
----	declare @UserId int
----	Set @UserId=(Select @@Identity)
----	Declare @i int
----	Set @i=0
----	while(@i<len(@RoleList))
----	begin
----	Insert Into aspnet_UsersInRoles(UserId,RoleId)Values(@UserId, substring(@RoleList,@i,charindex(',',@RoleList,@i)-@i))
----	Set @i=charindex(',',@RoleList,@i)+1
----	end
----end
----	RETURN



